package org.example.controller;

import org.example.bean.*;
import org.example.service.ModulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("modules")
public class ModulesController {
    @Autowired
    private ModulesService modulesService;

    @GetMapping("findModule.do")
    @ResponseBody
    public List<Modules> findModule(Integer m_id){
        return modulesService.findModule(m_id);
    }

    @GetMapping("findAll.do")
    @ResponseBody
    public List<ModuleList> findAll(){
        return modulesService.findAll();
    }

    @GetMapping("findAllProduct.do")
    @ResponseBody
    public List<Product> findAllProduct(){
        return modulesService.findAllProduct();
    }

    @GetMapping("findAllSupplier.do")
    @ResponseBody
    public List<Supplier> findAllSupplier(){
        return modulesService.findAllSupplier();
    }

    @GetMapping("addModuleList.do")
    @ResponseBody
    public Integer addModuleList(@RequestParam String m_name){
        return modulesService.addModuleList(m_name);
    }

    @GetMapping("addModules.do")
    @ResponseBody
    public boolean addModules(Integer m_id,String supplier,String breed, Integer finalist,Integer now_fix){

        return modulesService.addModules(m_id,supplier.replace("\"",""),breed.replace("\"",""),finalist,now_fix);
    }

    @GetMapping("del.do")
    @ResponseBody
    public boolean del(Integer m_id){
        return modulesService.del(m_id);
    }

    @GetMapping("shopAll.do")
    @ResponseBody
    public List<Ship> shopAll(){
        return modulesService.shopAll();
    }

    @GetMapping("ordersAll.do")
    @ResponseBody
    public Integer ordersAll(Orders orders){
        return modulesService.ordersAll(orders);
    }

    @GetMapping("addSup.do")
    @ResponseBody
    public Integer addSup(Sup sup){
        return modulesService.addSup(sup);
    }

    @GetMapping("supSer.do")
    @ResponseBody
    public List<Sup> supSer(Integer o_id){
        return modulesService.supSer(o_id);
    }

    @GetMapping("addOD.do")
    @ResponseBody
    public Integer addOD(@RequestParam Integer o_id,@RequestParam String breed,
                         @RequestParam Integer price,@RequestParam Integer purchase_quantity){
        return modulesService.addOD(o_id,breed,price,purchase_quantity);
    }

    //根据id查询OrderDetailed 表
    @GetMapping("OrderDetailedId.do")
    @ResponseBody
    public List<OrderDetailed> OrderDetailedId(Integer o_id){
        return modulesService.OrderDetailedId(o_id);
    }
    //根据breed和o_id修改价格
    @GetMapping("updateODPrice.do")
    @ResponseBody
    public boolean updateODPrice(@RequestParam Integer o_id,@RequestParam String breed,@RequestParam Integer price){
        return modulesService.updateODPrice(o_id,breed,price);
    }
    //根据o_id删除sup和orders表中数据
    @GetMapping("deleteSO.do")
    @ResponseBody
    public boolean deleteSO(Integer o_id){
        return modulesService.deleteSO(o_id);
    }
}
